package com.springmvc.springbootOne.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.springmvc.springbootOne.service.DemotestService;
import com.springmvc.springbootOne.util.Pagebean;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@RestController
@RequestMapping("/qualityControl/menu1")
public class DemotestController {

	@Autowired
	DemotestService demoService;

	// 只接受post请求
	@PostMapping("/findAll2")
	/*@SerializedField(excludes = {"id","password"})*/
	//@PathVariable String name 获取页面参数方法1
	//@RequestParam("petId") int petId 获取页面参数方法2
	public Pagebean findAll(HttpServletRequest request,int page,int rows) {
		System.out.println("99999999999999999");
		String salesTel = request.getParameter("salesTel");
		Map condition = new HashMap();
		String [] filterRules = request.getParameterValues("filterRules");
		if(filterRules!=null){
			//System.out.println(filterRules[0]);
			int start = filterRules[0].indexOf("{");
			if(start>-1){
				String childJson = filterRules[0].substring(start, filterRules[0].length()-1);
				System.out.println(childJson);
				JSONArray json = JSONArray.fromObject("["+childJson+"]");
				
				for(int i=0;i<json.size();i++){
					JSONObject job = json.getJSONObject(i);  
					//System.out.println(job.get("field")+","+job.get("value")) ; 
					if(job.get("value")!=null&&!job.get("value").toString().equals("")){
						condition.put(job.get("field"), job.get("value"));
					}
				}
			}
		}
		condition.put("salesTel", salesTel);
		Pagebean pg = new Pagebean(page,rows);
		pg.setCondition(condition);
		pg.setTotal(demoService.getWhitsInformationCount(pg));
		//session.setAttribute("aaa", "bbb");
		List list = new ArrayList();
		list =demoService.getWhitsInformation(pg);
		pg.setRows(list);
		return pg;
	}
	
}
